package com.googlecode.jsimplemarket.repository;

import java.io.Serializable;
import java.util.Collection;

/**
 *
 * @author alex
 */
public class GenericRestriction implements Serializable {

    private static final long serialVersionUID = 1L;

    public enum Op {

        EQ, GT, GE, LT, LE, LK, IN, NOT_NULL, IS_NULL
    }
    private GenericProperty property;
    private Comparable value;
    private Collection listValue;
    private Op op;

    public GenericRestriction(String propertyName, Collection listValue) {
        this.property = new GenericProperty(propertyName);
        this.listValue = listValue;
        this.op = Op.IN;
    }

    public GenericRestriction(GenericProperty property, Collection listValue) {
        this.property = property;
        this.listValue = listValue;
        this.op = Op.IN;
    }

    public GenericRestriction(String propertyName, Comparable value) {
        this.property = new GenericProperty(propertyName);
        this.value = value;
        this.op = Op.EQ;
    }

    public GenericRestriction(String propertyName, Comparable value, Op op) {
        this.property = new GenericProperty(propertyName);
        this.value = value;
        this.op = op;
    }

    public GenericRestriction(GenericProperty property, Comparable value) {
        this.property = property;
        this.value = value;
        this.op = Op.EQ;
    }

    public GenericRestriction(GenericProperty property, Comparable value, Op op) {
        this.property = property;
        this.value = value;
        this.op = op;
    }

    public Op getOp() {
        return op;
    }

    public void setOp(Op op) {
        this.op = op;
    }

    public GenericProperty getProperty() {
        return property;
    }

    public void setProperty(GenericProperty property) {
        this.property = property;
    }

    public Comparable getValue() {
        return value;
    }

    public void setValue(Comparable value) {
        this.value = value;
    }

    public Collection getListValue() {
        return listValue;
    }

    public void setListValue(Collection listValue) {
        this.listValue = listValue;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ((property == null) ? 0 : property.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        GenericRestriction other = (GenericRestriction) obj;
        if (property == null) {
            if (other.property != null) {
                return false;
            }
        } else if (!property.equals(other.property)) {
            return false;
        }
        return true;
    }
}
